﻿using System;
using BarManagement.DomainModel.Base.Logging;

namespace BarManagement.Infrastructure.Logging
{
    public class NLogLogger : ILogger
    {
        private static readonly Lazy<NLogLogger> LazyLogger = new Lazy<NLogLogger>(() => new NLogLogger());
        private static readonly Lazy<NLog.Logger> LazyNLogger = new Lazy<NLog.Logger>(NLog.LogManager.GetCurrentClassLogger);

        public static ILogger Instance { get { return LazyLogger.Value; } }

        private NLogLogger()
        { }

        public void Log(string message)
        { LazyNLogger.Value.Info(message); }

        public void Log(Exception ex)
        { LazyNLogger.Value.Error(ex); }

        public void Log(LogLevel logLevel, string message)
        {
            switch (logLevel)
            {
                case LogLevel.Trace:
                    LazyNLogger.Value.Trace(message);
                    break;
                case LogLevel.Debug:
                    LazyNLogger.Value.Debug(message);
                    break;
                case LogLevel.Info:
                    LazyNLogger.Value.Info(message);
                    break;
                case LogLevel.Warning:
                    LazyNLogger.Value.Warn(message);
                    break;
                case LogLevel.Error:
                    LazyNLogger.Value.Error(message);
                    break;
                case LogLevel.Fatal:
                    LazyNLogger.Value.Fatal(message);
                    break;
            }
        }

        public void Log(LogLevel logLevel, string message, params object[] args)
        {
            switch (logLevel)
            {
                case LogLevel.Trace:
                    LazyNLogger.Value.Trace(message, args);
                    break;
                case LogLevel.Debug:
                    LazyNLogger.Value.Debug(message, args);
                    break;
                case LogLevel.Info:
                    LazyNLogger.Value.Info(message, args);
                    break;
                case LogLevel.Warning:
                    LazyNLogger.Value.Warn(message, args);
                    break;
                case LogLevel.Error:
                    LazyNLogger.Value.Error(message, args);
                    break;
                case LogLevel.Fatal:
                    LazyNLogger.Value.Fatal(message, args);
                    break;
            }
        }

        public void Log(LogLevel logLevel, string message, Exception ex)
        {
            switch (logLevel)
            {
                case LogLevel.Trace:
                    LazyNLogger.Value.Trace(message, ex);
                    break;
                case LogLevel.Debug:
                    LazyNLogger.Value.Debug(message, ex);
                    break;
                case LogLevel.Info:
                    LazyNLogger.Value.Info(message, ex);
                    break;
                case LogLevel.Warning:
                    LazyNLogger.Value.Warn(message, ex);
                    break;
                case LogLevel.Error:
                    LazyNLogger.Value.Error(message, ex);
                    break;
                case LogLevel.Fatal:
                    LazyNLogger.Value.Fatal(message, ex);
                    break;
            }            
        }


     
    }
}
